package com.gwd.task.model;


import cn.hutool.core.bean.BeanUtil;
import com.gwd.task.entity.UserEntity;
import com.gwd.task.group.GroupInsert;
import com.gwd.task.group.GroupLogin;
import com.gwd.task.group.GroupUpdate;
import lombok.Data;
import lombok.NoArgsConstructor;

import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Null;

/**
 * @author zhiyongming
 * @date 2020/11/10 19:35
 */
@Data
@NoArgsConstructor
public class UserDTO {
    @NotNull(message = "用户id不能为空", groups = {GroupUpdate.class})
    @Null(message = "用户id不能传", groups = {GroupInsert.class})
    private Long userId;
    @NotBlank(message = "用户名不能为空", groups = {GroupInsert.class, GroupUpdate.class, GroupLogin.class})
    private String userName;
    @NotBlank(message = "密码不能为空", groups = {GroupInsert.class, GroupUpdate.class, GroupLogin.class})
    private String password;
    @NotBlank(message = "权限不能为空", groups = {GroupInsert.class, GroupUpdate.class})
    private String role;
    private Integer remove;

    public UserDTO(UserEntity userEntity) {
        if (userEntity==null) {
            return;
        }
        BeanUtil.copyProperties(userEntity, this);
    }
}
